let pageid = 0;
fetch('http://chst.vip:1234/api/getmoneyctrl?pageid='+pageid)
.then(function(c){
    return c.json()
})
.then(function(a){
    console.log(a);
    let str='';
    a.result.forEach(item => {
        let c = item.productImgSm.split(' ')[1].split('=')[3]
        str +=`<li productId="${item.productId}">
                    <div class="left">
                        <img src="${c}" alt="">
                    </div>
                    <div class="right">
                        <div class="top">
                            ${item.productName}<span>
                                ${item.productPinkage}
                            </span>
                        </div>
                        <div class="bottom">
                            <p>${item.productFrom}|${item.productTime}</p>
                            <p class="iconfont icon-xiaoxi">${item.productComCount}</p>
                        </div>
                    </div>
                </li>`
    });
    $('ul').html(str);
    let str1 = '';
    let pageZ = Math.floor(a.totalCount/a.pagesize);
    console.log(pageZ);
    for(var i=1;i<=pageZ;i++){
        str1 +=` <option value=${i}>${i}/${pageZ}</option>`
    }
    console.log(str1);
    $('#sw').html(str1)
    $('#sw').attr('pageZ',pageZ) 
    console.log( $('#sw').attr('pageZ'));
})
.then(function(){
    $('ul').on('click','li',function(){
        let productId = $(this).attr('productId')
        console.log(productId);
        location.href='./moneyctrl_1.html?productId='+productId;
    })
})


// 下一页
down.onclick=function(){
    pageid++;
    if(pageid>$('#sw').attr('pageZ')-1){
        pageid=$('#sw').attr('pageZ')-1;
    }
    fetch('http://chst.vip:1234/api/getmoneyctrl?pageid='+pageid)
    .then(function(c){
        return c.json()
    })
    .then(function(a){
        console.log(a);
        let str='';
        a.result.forEach(item => {
            let c = item.productImgSm.split(' ')[1].split('=')[3]
            str +=`<li>
                        <div class="left">
                            <img src="${c}" alt="">
                        </div>
                        <div class="right">
                            <div class="top">
                                ${item.productName}<span>
                                    ${item.productPinkage}
                                </span>
                            </div>
                            <div class="bottom">
                                <p>${item.productFrom}|${item.productTime}</p>
                                <p class="iconfont icon-xiaoxi">${item.productComCount}</p>
                            </div>
                        </div>
                    </li>`
        });
        $('ul').html(str);
        $('option')[pageid].selected=true;
    })
}

// 上一页
up.onclick=function(){
    pageid--;
    if(pageid<0){
        pageid=0;
    }
    fetch('http://chst.vip:1234/api/getmoneyctrl?pageid='+pageid)
    .then(function(c){
        return c.json()
    })
    .then(function(a){
        console.log(a);
        let str='';
        a.result.forEach(item => {
            let c = item.productImgSm.split(' ')[1].split('=')[3]
            str +=`<li>
                        <div class="left">
                            <img src="${c}" alt="">
                        </div>
                        <div class="right">
                            <div class="top">
                                ${item.productName}<span>
                                    ${item.productPinkage}
                                </span>
                            </div>
                            <div class="bottom">
                                <p>${item.productFrom}|${item.productTime}</p>
                                <p class="iconfont icon-xiaoxi">${item.productComCount}</p>
                            </div>
                        </div>
                    </li>`
        });
        $('ul').html(str);
        $('option')[pageid].selected=true;
    })
}

// 中间选择
sw.onclick=function(ev){
    let e = ev || window.event;
    let target = e.target || e.srcElement;
    console.log(target.value);
    pageid=target.value-1;
    fetch('http://chst.vip:1234/api/getmoneyctrl?pageid='+pageid)
    .then(function(c){
        return c.json()
    })
    .then(function(a){
        console.log(a);
        let str='';
        a.result.forEach(item => {
            let c = item.productImgSm.split(' ')[1].split('=')[3]
            str +=`<li>
                        <div class="left">
                            <img src="${c}" alt="">
                        </div>
                        <div class="right">
                            <div class="top">
                                ${item.productName}<span>
                                    ${item.productPinkage}
                                </span>
                            </div>
                            <div class="bottom">
                                <p>${item.productFrom}|${item.productTime}</p>
                                <p class="iconfont icon-xiaoxi">${item.productComCount}</p>
                            </div>
                        </div>
                    </li>`
        });
        $('ul').html(str);
        $('option')[pageid].selected=true;
    })
}